﻿@model DealKhuyenMaiV2.com.Models.Product
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Admin/Shared/_AdminLayout.cshtml";
}

<link href="@Url.Content("~/Content/DefaultThemes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
<script src="../../Scripts/ckfinder/ckfinder.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.11.min.js" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="../../Scripts/ckeditor/ckeditor.js" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        $('.end').datepicker();
        $('.start').datepicker();
        $.tabs('#tabs a');
        
    });
    image_row = 1;
  
    function upload(id) {
        var finder = new CKFinder();
        finder.selectActionFunction = function (fileUrl) {
            //var imageUrl = "/Image/GetBase64Image?curpath=" + encodeURIComponent(fileUrl);
            $('#preview' + id).replaceWith('<img src="' + fileUrl + '" alt="" id="preview' + id + '" class="image" onclick = "upload(' + id + ');" />');
            $('#image' + id).val(fileUrl);
        };
        finder.popup();

    }

    function addImage() {
        html = '<tbody id="image_row' + image_row + '">';
        html += '<tr>';
        html += '<td class="left"><input type="hidden" name="product_image[' + image_row + ']" value="" id="image' + image_row + '" /><img src="../../ContentAdmin/DefaultThemes/image/no_image-100x100.jpg" alt="" id="preview' + image_row + '" name="preview' + image_row + '" onclick = "upload(' + image_row + ');" class="image" /></td>';
        html += '<td class="left"><a onclick="$(\'#image_row' + image_row + '\').remove();" class="button"><span>Xóa</span></a></td>';
        html += '</tr>';
        html += '</tbody>';

        $('#images tfoot').before(html);
        $('#NumberofPicture').val(image_row.toString());
        image_row++;
        
    }   
</script>
<div class="breadcrumb">
        @Html.ActionLink("Trang Chủ", "Index", "Admin")::@Html.ActionLink("Sản Phẩm", "Index", "ProductManager")
    </div>
<div class="box">
    <div class="left">
    </div>
    <div class="right">
    </div>
    <div class="heading">
        <h1 style="background-image: url(../../ContentAdmin/DefaultThemes/image/home.png);">
            Quản trị sản phẩm</h1>
        <div class="buttons">
           <a onclick="$('form').submit();" class="button"><span>Cập Nhật</span></a>
             <a  href="@Url.Action("Index")" class="button"><span>Hủy</span></a>
         </div>

    </div>
    <div class="content">
    
        @using (Html.BeginForm())
        {
            @Html.ValidationSummary(true)
   
            <div id="tabs" class="htabs">
                <a tab="#tab_general" class="selected">Tổng quan</a>
                <a tab="#tab_Data" class="">Dữ Liệu</a>
                <a tab="#tab_image" class="">Hình ảnh</a>
                </div>
            <div id="tab_general" style="display: block;">
                <table class="form">
                    @Html.HiddenFor(model => model.IDProduct)
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.NameProduct) :
                        </td>
                        <td>
                            @Html.TextBoxFor(model => model.NameProduct, new { @style = "width : 500px" })
                            @Html.ValidationMessageFor(model => model.NameProduct)
                        </td>
                    </tr>
                    
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.Condition) :
                        </td>
                        <td>
                            @Html.TextAreaFor(model => model.Condition, new { @class = "ckeditor" })
                            @Html.ValidationMessageFor(model => model.Condition)
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.Summary) :
                        </td>
                        <td>
                            @Html.TextAreaFor(model => model.Summary, new { @class = "ckeditor" })
                            @Html.ValidationMessageFor(model => model.Summary)
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.Description) :
                        </td>
                        <td>
                            @Html.TextAreaFor(model => model.Description, new { @class = "ckeditor" })
                            @Html.ValidationMessageFor(model => model.Description)
                        </td>
                    </tr>


                    
                </table>
               
            </div>
            <div id="tab_Data" style="display: block;">
            <table class="form">
                 
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.Price) :
                        </td>
                        <td>
                            @Html.EditorFor(model => model.Price)
                            @Html.ValidationMessageFor(model => model.Price)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.Discount) :
                        </td>
                        <td>
                            @Html.EditorFor(model => model.Discount)
                            @Html.ValidationMessageFor(model => model.Discount)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span  class="required">*</span> @Html.LabelFor(model => model.Date_start) :
                        </td>
                        <td >
                            @Html.TextBoxFor(model => model.Date_start, new { @class = "start" })
                            @Html.ValidationMessageFor(model => model.Date_start)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.Date_end) :
                        </td>
                        <td>
                            @Html.TextBoxFor(model => model.Date_end, new { @class = "end" })
                            @Html.ValidationMessageFor(model => model.Date_end)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.IDAccount, "Account")
                            :
                        </td>
                        <td>
                            @Html.DropDownList("IDAccount")
                            @Html.ValidationMessageFor(model => model.IDAccount)
                        </td>
                    </tr>
                
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.Shipping) :
                        </td>
                        <td>
                            @Html.EditorFor(model => model.Shipping)
                            @Html.ValidationMessageFor(model => model.Shipping)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span>@Html.LabelFor(model => model.IDStatus, "StatusProduct")
                            :
                        </td>
                        <td>
                            @Html.DropDownList("IDStatus")
                            @Html.ValidationMessageFor(model => model.IDStatus)
                        </td>
                    </tr>
                 
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.IDCatalogy, "Catalogy")
                            :
                        </td>
                        <td>
                            @Html.DropDownList("IDCatalogy")
                            @Html.ValidationMessageFor(model => model.IDCatalogy)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.SortOrder) :
                        </td>
                        <td>
                            @Html.EditorFor(model => model.SortOrder)
                            @Html.ValidationMessageFor(model => model.SortOrder)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.TotalOfNumber) :
                        </td>
                        <td>
                            @Html.EditorFor(model => model.TotalOfNumber)
                            @Html.ValidationMessageFor(model => model.TotalOfNumber)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.NumberOfPurchased)
                            :
                        </td>
                        <td>
                            @Html.EditorFor(model => model.NumberOfPurchased)
                            @Html.ValidationMessageFor(model => model.NumberOfPurchased)
                        </td>
                    </tr>
                    
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.AllowableNumber) :
                        </td>
                        <td>
                            @Html.EditorFor(model => model.AllowableNumber)
                            @Html.ValidationMessageFor(model => model.AllowableNumber)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span> @Html.LabelFor(model => model.IDProvince, "Province")
                            :
                        </td>
                        <td>
                            @Html.DropDownList("IDProvince")
                            @Html.ValidationMessageFor(model => model.IDProvince)
                        </td>
                    </tr>
                </table>
            </div>
            <div id="tab_image" style="display: block; ">
        <table id="images" class="list">
        <input type="hidden" name="NumberofPicture" id="NumberofPicture" value="1"/>  
          <thead>
            <tr>
              <td class="left">Hình:<br><span class="help">Click vào hình ảnh để thay đổi nó.</span></td>
              <td></td>
            </tr>
          </thead>
          @for(int i = 0 ;i < Model.Images.Count ; i++)
          {
              <tbody id="image_row@(i+1)">
                  <tr>
                      <td class="left">
                          <input type="hidden" name="product_image[@(i+1)]" value="@(Model.Images.ElementAt(i).Path)" id="image@(i+1)"/><img src="@(Model.Images.ElementAt(i).Path)"
                              alt="" id="preview@(i+1)" name ="preview@(i+1)" class="image" onclick="upload(@(i+1));">
                      </td>
                      <td class="left">
                          <a onclick="$('#image_row@(i+1)').remove();$('#NumberofPicture').val(image_row.toString());" class="button"><span>Xóa</span></a>
                      </td>
                  </tr>
              </tbody>
              <script>

                  $('#NumberofPicture').val(image_row.toString());
                  image_row +=1;
                  
              </script>
          }
                           
         <tfoot>
            <tr>
              <td></td>
              <td class="left"><a onclick="addImage();" class="button"><span>Thêm hình</span></a></td>
            </tr>
          </tfoot>
        </table>
              

      </div>
    
        }
       
    </div>
</div>
